import { createRouter, createWebHashHistory, RouteLocationNormalized, RouteRecordRaw } from 'vue-router'

// 定义路由配置
const routes: RouteRecordRaw[] = [
    { 
        path: '/', 
        name: 'index',
        component: () => import('@/layout/index.vue'),
        redirect: '/home',
        children: [
            {
                path: 'home',
                name: 'home',
                component: () => import('@/views/home.vue')
            },
            {
                path: 'connection',
                name: 'connection',
                component: () => import('@/views/connection/index.vue'),
                children: [
                    {
                        path: 'selection',
                        name: 'connSelection',
                        component: () => import('@/views/connection/ConnSelection.vue')
                    },
                    {
                        path: 'form',
                        name: 'connectionForm',
                        component: () => import('@/views/connection/ConnAddForm.vue'),
                        props: (route: RouteLocationNormalized) => ({ 
                            dbType: route.query.type,
                            dbLogo: route.query.logo,
                            id: route.query.id,
                            enterType: route.query.enterType,
                        })
                    },
                    {
                        path: 'preview/:id',
                        name: 'dataPreview',
                        component: () => import('@/views/connection/DataPreview.vue'),
                        props: true
                    },
                ]
            },
            {
                path: 'dataset',
                name: 'dataset',
                component: () => import('@/views/dataset/index.vue')
            },
            {
                path: 'insight',
                name: 'insight',
                component: () => import('@/views/insight/index.vue')
            },
        ]
    }
]

// 创建路由实例
export const router = createRouter({
    history: createWebHashHistory(),
    routes
})